import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import { errorHandler, systemErrorHandler } from '../utils/error-handle'
import { successHandle } from '../utils/success-handle'
import useRoutes from '../router'

const app = new Koa()

// 注册中间件
app.use(bodyParser())
useRoutes(app)

// 注册自定义事件
app.on('error', errorHandler)
app.on('systemError', systemErrorHandler)
app.on('success', successHandle)
export default app